#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include<vector>
#include<cstdio>
using namespace std;

int main() {
    int n, V;
    scanf("%d %d", &n, &V);
    int v[n], w[n];
    for (int i = 0;i <= n;i++)
    {
        scanf("%d %d", &v[i], &w[i]);
    }
    vector<vector<int>> dp1(n + 1, vector<int>(V + 1, 0));
    vector<vector<int>> dp2(n + 1, vector<int>(V + 1, 0));
    for (int i = 1;i <= V;i++) dp2[0][i] = -1;
    for (int i = 1;i <= n;i++)
    {
        for (int j = 1;j <= V;j++)
        {
            dp1[i][j] = dp1[i - 1][j];
            if (j - v[i - 1] >= 0) dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - v[i - 1]] + w[i - 1]);

            dp2[i][j] = dp2[i - 1][j];
            if (dp2[i - 1][j - v[i - 1]] != -1 && j - v[i - 1] >= 0)
                dp2[i][j] = max(dp2[i][j], dp2[i - 1][j - v[i - 1]] + w[i - 1]);
        }
    }
    printf("%d\n", dp1[n][V]);
    if (dp2[n][V] == -1) printf("0\n");
    else printf("%d\n", dp2[n][V]);
}